//
//  AppDelegate.m
//  yidianyuanqicelue
//
//  Created by LK-IOS on 2018/6/27.
//  Copyright © 2018年 LK-YDIOS. All rights reserved.
//

#import "AppDelegate.h"
#import "YDABaseTabBarController.h"
#import "YDBaseTabBarController.h"
#import "SYNewFeatureController.h"
#import "AppDelegate+JPushDelegate.h"
#import <Bugly/Bugly.h>

#import "YDNewFeatureController.h"



@interface AppDelegate ()

@end

@implementation AppDelegate


- (BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:(NSDictionary *)launchOptions
{
    [NSThread sleepForTimeInterval:3];
    
    [[SYVersionManger sharedInstance] loadAppVersionInformation];
    
    if ([[SYUserDataManger sharedInstance] userTokenIsOver]) {
        [SYUserInformation sharedInstance].isLogin = NO;
    }else{
        [SYUserInformation sharedInstance].isLogin = YES;
    }
    
    
#if DEBUG
    BuglyConfig *config = [[BuglyConfig alloc] init];
    config.debugMode = YES;
    [Bugly startWithAppId:@"b78dfbb233"
        developmentDevice:NO
                   config:config];
#endif
    //Bugly检测崩溃
    [Bugly startWithAppId:@"b78dfbb233"];
    [Bugly setUserIdentifier:[SYUserDataManger sharedInstance].getUerPhone ?: @"0"];
    
    
    //    //提交
    //    self.window = [[UIWindow alloc] initWithFrame:[UIScreen mainScreen].bounds];
    //    if ([[SYVersionManger sharedInstance] isCannormalJumpTab]) {
    //        //初始化极光推送
    //        [self init_jpushWithOptions:launchOptions window:self.window];
    //    }
    //    [self checkVersion];
    
    
    //正常
    self.window = [[UIWindow alloc] initWithFrame:[UIScreen mainScreen].bounds];
    [self init_jpushWithOptions:launchOptions window:self.window];
    [self qiyeCheckVersion];
    
    
    //空壳
//    self.window = [[UIWindow alloc] initWithFrame:[UIScreen mainScreen].bounds];
//    self.window.rootViewController = [[YDABaseTabBarController alloc] init];
//    [self.window makeKeyAndVisible];
    
    return YES;
    
}


-(void)checkVersion
{
    //之前版本信息及当前版本信息
    NSString *preVersion = [[NSUserDefaults standardUserDefaults] objectForKey:@"versionKey"];
    NSString *curVersion = [NSBundle mainBundle].infoDictionary[@"CFBundleShortVersionString"];
    if ([preVersion isEqualToString:curVersion]) {//版本信息相同,正常启动
        
        if ([[SYVersionManger sharedInstance] isCannormalJumpTab]) {
            self.window.rootViewController = [[YDBaseTabBarController alloc] init];
        }else{
            self.window.rootViewController = [[YDABaseTabBarController alloc] init];
        }
        
        [self.window makeKeyAndVisible];
        
    }else{//版本信息不同,加载引导页
        
        SYNewFeatureController *vc = [[SYNewFeatureController alloc] init];
        self.window.rootViewController = vc;
        [self.window makeKeyAndVisible];
        //保存之前的版本
        [[NSUserDefaults standardUserDefaults] setObject:curVersion forKey:@"versionKey"];
        [[NSUserDefaults standardUserDefaults] synchronize];
    }
}


-(void)qiyeCheckVersion
{
    //之前版本信息及当前版本信息
    NSString *preVersion = [[NSUserDefaults standardUserDefaults] objectForKey:@"versionKey"];
    NSString *curVersion = [NSBundle mainBundle].infoDictionary[@"CFBundleShortVersionString"];
    if ([preVersion isEqualToString:curVersion]) {//版本信息相同,正常启动
        
        self.window.rootViewController = [[YDBaseTabBarController alloc] init];
        [self.window makeKeyAndVisible];
        
    }else{//版本信息不同,加载引导页
        
        YDNewFeatureController *vc = [[YDNewFeatureController alloc] init];
        self.window.rootViewController = vc;
        [self.window makeKeyAndVisible];
        //保存之前的版本
        [[NSUserDefaults standardUserDefaults] setObject:curVersion forKey:@"versionKey"];
        [[NSUserDefaults standardUserDefaults] synchronize];
    }
    
    
}



@end
